package com.nl.storage.config;

import com.nl.storage.consts.CloudService;
import com.nl.storage.exception.CloudStorageException;
import com.nl.storage.properties.CloudStorageConfig;
import com.nl.storage.service.AliyunCloudStorageService;
import com.nl.storage.service.CloudStorageService;
import com.nl.storage.service.QcloudCloudStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * .
 *
 * @author xht.
 * @createTime 2021年10月27日 10:12:00
 */
@Configuration
@EnableConfigurationProperties(CloudStorageConfig.class)
public class StorageFactoryConfig {

    @Autowired
    private CloudStorageConfig config;

    @Bean(name = "cloudStorageService")
    public CloudStorageService build() {
        if (config.getType() == CloudService.ALIYUN.getValue()) {
            return new AliyunCloudStorageService(config);
        }
        if (config.getType() == CloudService.QCLOUD.getValue()) {
            return new QcloudCloudStorageService(config);
        }
        throw new CloudStorageException("类型不存在");
    }


}
